﻿using Mathmall.Administration.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Mathmall.Administration.Data
{
    public class AttrGroupEntityTypeConfiguration : IEntityTypeConfiguration<AttrGroup>
    {
        public void Configure(EntityTypeBuilder<AttrGroup> builder)
        {
            // 不使用output子句
            builder.ToTable(table => table.UseSqlOutputClause(false));

            builder
                .ToTable(nameof(AttrGroup))
                .ToTable(tableBuilder => tableBuilder.HasComment("属性分组"));

            builder
                .HasKey(atttrGroup => atttrGroup.AttrGroupID)
                .HasName("AttrGroupID");

            builder
                .Property(atttrGroup => atttrGroup.AttrGroupName)
                .HasColumnName("AttrGroupName")
                .HasColumnType("nvarchar(20)")
                .HasComment("组名")
                .IsRequired(false);

            builder
                .Property(atttrGroup => atttrGroup.Sort)
                .HasColumnName("Sort")
                .HasColumnType("int")
                .HasComment("排序")
                .IsRequired(false);

            builder
                .Property(atttrGroup => atttrGroup.Description)
                .HasColumnName("Description")
                .HasColumnType("nvarchar(255)")
                .HasComment("描述")
                .IsRequired(false);

            builder
                .Property(atttrGroup => atttrGroup.Icon)
                .HasColumnName("Icon")
                .HasColumnType("varchar(255)")
                .HasComment("组图标")
                .IsRequired(false);

            builder
                .Property(atttrGroup => atttrGroup.CatalogID)
                .HasColumnName("CatalogID")
                .HasColumnType("int")
                .HasComment("所属分类id")
                .IsRequired(true);

            builder
                .Property(atttrGroup => atttrGroup.CreateTime)
                .HasColumnName("CreateTime")
                .HasColumnType("datetime")
                .HasComment("创建时间")
                .IsRequired(false);

            builder
                .Property(atttrGroup => atttrGroup.LastUpdateTime)
                .HasColumnName("LastUpdateTime")
                .HasColumnType("datetime")
                .HasComment("最后更新时间")
                .IsRequired(false);
        }
    }
}